#ifndef PANNERWIDGET_H
#define PANNERWIDGET_H

#include <QImage>
#include <QWidget>
#include <QRect>

class PannerWidget : public QWidget
{
Q_OBJECT
public:
    explicit PannerWidget(QWidget *parent = 0, const QSize& viewportSize = QSize());
    void setImage(const QImage& image);
    void setZoom(double zoom);

protected:
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *event);

signals:
    void signalRectangleChanged(const QRect& rectangle);

public slots:
    void slotSizeChanged(const QSize& size);

protected:
    void mouseMoveEvent(QMouseEvent *);
    void mousePressEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);

private:
    static double aspectRatio(int sourceWidth, int destWidth, int sourceHeight, int destHeight);
    void scaleImage();
    void setRectangleSize();
    void updateLocation(const QPoint& pos);

private:
    QImage m_image;
    double m_imageScaleRatio;
    bool m_insideRect;
    QPoint m_prevPosition;
    QRect  m_rectangle;
    QSize  m_viewportSize;
    double m_zoom;
};

#endif // PANNERWIDGET_H
